<template>
	<view class="recharge" >
		<view class="recharge-content">
			<view class="cell" >
				<view class="cell-title"> 主网地址</view>
				<view class="cell-content">
				<uv-input  placeholder="请输入您的主网地址" class="recharge-input"  placeholderStyle="#5E636E" v-model="a" >
				</uv-input>
				</view>
			</view>
			<view class="cell" >
				<view class="cell-title">钱包地址</view>
				<view class="cell-content">
				<uv-input  placeholder="请输入您的钱包地址" class="recharge-input" placeholderStyle="#5E636E" v-model="b" >
			   </uv-input>
				</view>
			</view>
		</view>

		<view class="num-content">
			<view class="cell" >
				<view class="cell-title"> <view>提现数量</view>  <view class="yellow-text">全部提现</view> </view>
				<view class="cell-content">
				<uv-input  placeholder="请输入您的提现数量" class="recharge-input"  placeholderStyle="#5E636E" v-model="a" >
					<template v-slot:suffix>
						<view class="num-input-text">U D S T</view>
					</template>
				</uv-input>
				</view>
			</view>
			<view class="recharge-tip">
				<view>限额数量：<text class="yellow-text">{{}} UDST</text></view>
				<view>到账数量：<text class="yellow-text">{{}} UDST</text></view>
		   </view>

		</view>
		<view class="pay-next-btn">
			<button class="pay-btn" @click="recharge">确认提现</button> 
		</view>
	</view>
	<!-- <view>
		<view>
			<uv-form class="padding-lr32" label-position="top" label-width="150">
				<uv-form-item label="提现金额">
					<uv-input :placeholder="withdrawPlaceholder()" v-model="amount" type="number" :clearable="false">
						<template v-slot:suffix>
							<uv-button type="primary" text="全部" size="mini" @click="allAmount"></uv-button>
						</template>
					</uv-input>
				</uv-form-item>
				<uv-form-item label="支付密码">
					<uv-input placeholder="请输入支付密码" v-model="payPwd" :clearable="false">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="">
					<view class="pay-ways">
						<view class="pay-way" @click="changeBalanceType('1')">
							<view class="pay-way-icon">
								<uv-icon name="checkmark-circle-fill"
									:color="balanceType == '1' ? '#2979ff' : '#cecece'" size="24"></uv-icon>
							</view>
							<view class="pay-way-right">
								<view class="pay-way-title">账户余额</view>
								<view class="pay-way-value">可用<text>{{memberInfo.accountBalance}}</text>USDT</view>
							</view>
						</view>
					</view>
				</uv-form-item>
			</uv-form>

		</view>
		<view class="fixed-bottom">
			<view class="fixed-bottom-inner">
				<view class="actual-amount" v-show="withdrawSetting">
					<view class="actual-amount-l">
						提现收取{{withdrawSetting.withdrawRate}}%的手续费，单笔手续费最低为{{withdrawSetting.withdrawMinHandlingFee}}
					</view>
				</view>
				<view class="actual-amount">
					<view class="actual-amount-l">预计到账金额</view>
					<view class="actual-amount-r">{{actualAmount}} USDT</view>
				</view>
				<uv-button type="primary" size="large" @click="withdraw" :disabled="!allowWithdrawFlag">申请提现</uv-button>
			</view>
		</view>
	</view> -->
</template>

<script>
	export default {
		data() {
			return {
				allowWithdrawFlag: false,
				memberInfo: '',
				balanceType: '1',
				amount: '',
				payPwd: '',
				withdrawSetting: '',
				withdrawWays: [],
				withdrawWay: '',

			}
		},
		computed: {
			actualAmount: function() {
				var actualAmount = 0;
				if (this.memberInfo === null || this.memberInfo === '') {
					return actualAmount;
				}
				if (this.amount === null || this.amount === '') {
					return actualAmount;
				}
				if (this.withdrawSetting === null || this.withdrawSetting === '') {
					return actualAmount;
				}
				var handlingFee = this.amount * this.withdrawSetting.withdrawRate * 0.01;
				if (handlingFee < this.withdrawSetting.withdrawMinHandlingFee) {
					handlingFee = this.withdrawSetting.withdrawMinHandlingFee;
				}
				actualAmount = parseFloat(Number(this.amount - handlingFee).toFixed(2));
				if (actualAmount <= 0) {
					return 0;
				}
				return actualAmount;
			},
		},
		onNavigationBarButtonTap(e) {
			uni.navigateTo({
				url: '../withdrawRecord/withdrawRecord'
			});
		},
		onLoad() {
			this.getMemberWithdrawSetting();
		},
		onShow() {
			this.getMemberInfo();
		},
		methods: {

			changeBalanceType(balanceType) {
				this.balanceType = balanceType;
			},

			withdrawPlaceholder() {
				if (this.withdrawSetting) {
					return '最小提现金额为 ' + this.withdrawSetting.withdrawMinAmount;
				}
			},

			getMemberWithdrawSetting() {
				var that = this;
				uni.$uv.http.get('/setting/getMemberWithdrawSetting').then(res => {
					that.withdrawSetting = res.data;
					that.allowWithdrawFlag = that.withdrawSetting.allowWithdrawFlag;
					if (!that.allowWithdrawFlag) {
						uni.showToast({
							title: "提现时间在" + that.withdrawSetting.withdrawTimeStart + "到" + that
								.withdrawSetting.withdrawTimeEnd,
							icon: "none"
						});
						return;
					}
				});
			},

			getMemberInfo() {
				var that = this;
				uni.$uv.http.get('/member/getMemberInfo').then(res => {
					that.memberInfo = res.data;
				});
			},

			allAmount() {
				this.amount = this.balance;
			},

			withdrawInner() {
				var that = this;
				uni.$uv.http.post('/memberWithdraw/withdraw', {
					amount: that.amount,
					payPwd: that.payPwd,
				}).then(res => {
					uni.showToast({
						icon: 'success',
						title: '操作成功!',
						duration: 2000,
						complete: function() {
							setTimeout(() => {
								uni.navigateBack();
							}, 2000);
						}
					});
				});
			},

			withdraw() {
				var that = this;
				if (that.amount === null || that.amount === "") {
					uni.showToast({
						title: "请输入提现金额",
						icon: "none"
					});
					return;
				}
				if (that.payPwd === null || that.payPwd === "") {
					uni.showToast({
						title: "请输入支付密码",
						icon: "none"
					});
					return;
				}
				that.withdrawInner();
			},
		}
	}
</script>

<style scoped lang="less">
    .yellow-text{
		color:  #E4D494
	}
	 page {
		background: #0B1327;
		color: #fff;
		font-size: 28rpx;
	}
	.recharge{
		padding: 20rpx 32rpx;
		.recharge-content{
   			background: #18273D;
			border-radius: 28rpx;
			padding: 28rpx 32rpx;
		}
		.cell{
			margin-bottom: 40rpx;
			&:last-child{
				margin-bottom: 0;
			}
			.cell-title{
				color: #5D6777;
			    font-size: 24rpx;
				line-height: 24rpx;
				margin-bottom: 16rpx;
			}
			.cell-content{
			   .recharge-input{
				    height: 92rpx;
					border: none;
					background: #192131;
					border-radius: 20rpx;
					color: #E4D494;
					/deep/ .uni-input-input{
						color: #fff;
					}
				}


			}
		}
	}

	.num-content{
		margin-top: 28rpx;
		background: #18273D;
			border-radius: 28rpx;
			padding: 28rpx 32rpx;
			.num-input-text{
				font-weight: 600;
				font-size: 52rpx;
				color: #FFFFFF;
				line-height: 52rpx;
			}
		.cell{
			margin-bottom: 40rpx;
			&:last-child{
				margin-bottom: 0;
			}
			.cell-title{
				color: #5D6777;
			    font-size: 24rpx;
				line-height: 24rpx;
				margin-bottom: 16rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}
			.cell-content{
			   .recharge-input{
				    height: 92rpx;
					border: none;
					background: #192131;
					border-radius: 20rpx;
					/deep/ .uni-input-input{
						color: #757A83;
						font-weight: 600;
						font-size: 52rpx;
					}
				}


			}
		}
		.recharge-tip{
			color: #545967;
			font-size: 24rpx;
			line-height: 24rpx;
			view{
				margin-bottom: 20rpx;
			}
		}
	}


	.pay-next-btn {
		padding: 0px 40rpx;
		position: fixed;
		bottom: 60rpx;
		left: 0;
		right: 0;
        .pay-btn{
			color: #0B1327;
			font-weight: 900;
			font-size: 28rpx;
			height: 100rpx;
			line-height:100rpx;
			background: linear-gradient( 180deg, #FFF9C3 0%, #FFB637 100%);
		    border-radius: 50rpx;
		}
			
	}
</style>